using Microsoft.EntityFrameworkCore;
using SheLife.Domain.Entities;
using SheLife.Domain.Interfaces;

namespace SheLife.Infrastructure.Repositories;

public class HealthRecordRepository : Repository<HealthRecord>, IHealthRecordRepository
{
    public HealthRecordRepository(ApplicationDbContext context) : base(context)
    {
    }

    public async Task<IEnumerable<HealthRecord>> GetByUserIdAsync(int userId)
    {
        return await _dbSet
            .Where(hr => hr.UserId == userId && !hr.IsDeleted)
            .OrderByDescending(hr => hr.RecordDate)
            .ToListAsync();
    }

    public async Task<IEnumerable<HealthRecord>> GetByUserIdAndTypeAsync(int userId, string recordType)
    {
        return await _dbSet
            .Where(hr => hr.UserId == userId && hr.RecordType == recordType && !hr.IsDeleted)
            .OrderByDescending(hr => hr.RecordDate)
            .ToListAsync();
    }

    public async Task<IEnumerable<HealthRecord>> GetByUserIdAndDateRangeAsync(int userId, DateTime startDate, DateTime endDate)
    {
        return await _dbSet
            .Where(hr => hr.UserId == userId && 
                        hr.RecordDate >= startDate && 
                        hr.RecordDate <= endDate && 
                        !hr.IsDeleted)
            .OrderByDescending(hr => hr.RecordDate)
            .ToListAsync();
    }
}